package com.work.demo.entity;

import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

@Data
public class Demo {
	private String name;
	private int age;

	public static List<Demo> getDemo1() {
		Demo demo = new Demo();
		demo.setAge(11);
		demo.setName("Linya1");
		Demo demo2 = new Demo();
		demo2.setAge(13);
		demo2.setName("Linya1");
		List<Demo> demoList = new ArrayList<>();
		demoList.add(demo);
		demoList.add(demo2);
		return demoList;
	}

	public static List<Demo> getDemo2() {
		Demo demo = new Demo();
		demo.setAge(11);
		demo.setName("张");
		Demo demo2 = new Demo();
		demo2.setAge(12);
		demo2.setName("李");
		List<Demo> demoList = new ArrayList<>();
		demoList.add(demo);
		demoList.add(demo2);
		return demoList;
	}

	public static void main(String[] args) {
//        List<Demo> demoList = getDemo1();
//        List<Demo> demos = getDemo2();
//
//        List<String> stringList = new ArrayList<>();
//
//        stringList.add("Linya1");
//        stringList.add("Linya2");
//        stringList.add("Linya3");
//        stringList.add("Linya4");
//        stringList.add("Linya5");
//        stringList.add("Linya6");
//
//
//        List<Demo> collect1 = demoList.stream().filter(demo -> demo.getAge() == 11).collect(Collectors.toList());
//        collect1.forEach(System.out::println);
		ReentrantLock reentrantLock = new ReentrantLock();

		reentrantLock.lock();
		try {
			new Thread(() -> {

//                try {
//                    Thread.sleep(1000);
//                    System.out.println("jjjjjj");
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
				System.out.println("jjjjjj");

			}).start();


			new Thread(() -> {
				System.out.println("456456456456564");
			}).start();

		} finally {
			reentrantLock.unlock();
		}


		byte[] bytes = Demo.hexString2Bytes("0A");
		String s = Demo.bytesToHexString(bytes);
		System.out.println(Arrays.toString(bytes));
		System.out.println(s.toUpperCase());

	}

	/**
	 * 十六进制转字节数组
	 *
	 * @param src
	 * @return
	 */
	public static byte[] hexString2Bytes(String src) {
		int l = src.length() / 2;
		byte[] ret = new byte[l];
		for (int i = 0; i < l; i++) {
			ret[i] = (byte) Integer
							.valueOf(src.substring(i * 2, i * 2 + 2), 16).byteValue();
		}
		return ret;
	}

	/**
	 * 字节数组转16进制字符串
	 */
	public static String bytesToHexString(byte[] bArr) {
		if (bArr == null) {
			return null;
		}
		StringBuffer sb = new StringBuffer(bArr.length);
		String sTmp;

		for (int i = 0; i < bArr.length; i++) {
			sTmp = Integer.toHexString(0xFF & bArr[i]);
			if (sTmp.length() < 2) {
				sb.append(0);
			}
			sb.append(sTmp);
		}

		return sb.toString();
	}

}
